package cn.clementine.core.entity;

import lombok.Data;

import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

@Data
public class MemInfo {
    private long GB = 1024 * 1024 * 1024;
    // 进程CPU使用率
    private String process_cpu_load;
    // 系统CPU使用率
    private String system_cpu_load;
    // 物理内存总量
    private String total_physical_memory;
    // 物理内存剩余可用量
    private String free_physical_memory_size;
    // 内存使用率
    private String memory_usage_rate;
    // 交换空间总量
    private String total_swap_space;
    // 交换空间剩余可用量
    private String free_swap_space_size;
    // CPU核心数
    private String available_processors;
    // 已提交虚拟内存量
    private String committed_virtual_memory_size;
    // 进程已使用CPU时间
    private String process_cpu_time;
    public MemInfo(){
        OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
        process_cpu_load = operatingSystemMXBean.getProcessCpuLoad()* 100+"%";
        system_cpu_load = operatingSystemMXBean.getCpuLoad()* 100+"%";
        total_physical_memory = operatingSystemMXBean.getTotalMemorySize()/GB+"GB";
        free_physical_memory_size = operatingSystemMXBean.getFreeMemorySize()/GB+"GB";
        memory_usage_rate = (double)100*operatingSystemMXBean.getFreeMemorySize()/operatingSystemMXBean.getTotalMemorySize()+"%";
        total_swap_space = operatingSystemMXBean.getTotalSwapSpaceSize()/GB+"GB";
        free_swap_space_size = operatingSystemMXBean.getFreeSwapSpaceSize()/GB+"GB";
        available_processors = String.valueOf(operatingSystemMXBean.getAvailableProcessors());
        committed_virtual_memory_size = String.valueOf(operatingSystemMXBean.getCommittedVirtualMemorySize());
        process_cpu_time = operatingSystemMXBean.getProcessCpuTime()/1000000000.0+" seconds";
    }
}
